import Cookies from 'js-cookie'
import Config from '@/settings'

const Token = Config.Token
const Dic = Config.Dic
export function getToken() {
  return Cookies.get(Token)
}

export function setToken(token) {
  return Cookies.set(Token, token)
}

export function removeToken() {
  return Cookies.remove(Token)
}

export function getDic(key) {
  const json = JSON.parse(localStorage.getItem(Dic))
  const data = json.filter(item => item.code === key)
  if (data && data[0]) {
    const details = data[0].details
    if (details) {
      const dics = [{ value: '', label: '全部' }]
      details.forEach(element => {
        dics.push({ value: element.code, label: element.value })
      })
      return dics
    }
    return []
  }
}

export function setDic(dics) {
  return localStorage.setItem(Dic, JSON.stringify(dics))
}

